﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.Linq;
using Blog.DAL;
namespace Blog.BAL
{
    public partial class member:tblMembers
    {
        public bool create_folder(string folder_name,string serverDir)
        {
            string newPath = Path.Combine(serverDir,folder_name);
            if(!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
                return true;
            }
            return false;

        }

        public List<string> gender()
        {
            
            List<string> list = new List<string>();
            list.Add("Nam");
            list.Add("Nữ");
            list.Add("Khác");
            return list;
        }

        public void create_file(string content)
        { 
        
        }
        public int check_username(string username)
        {
            DB db = new DB();
            var query = from u in db.tblMembers where u.username.Equals(username) select u.mem_id;
            return query.Count();
        }

        public int user_info(string username,string password)
        {
            try
            {
                DB db = new DB();
                var a = db.sp_login(username, password).SingleOrDefault();
                if (a.mem_id > 0)
                {
                    return a.mem_id;
                }
            }
            catch
            {

                return 0;
            }
            return 0;
        }
        //Get basic member's infomation
        public List<sp_get_member_by_idResult> get_mem_info(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_member_by_id(mem_id).ToList();
        }
        public string get_avarta(int mem_id)
        {
            DB db = new DB();
            var u = db.sp_get_avarta(mem_id).ToList();
            if (u.Count() > 0)
                return u[0].avarta.ToString();
            return "0";
        }
        public int get_mem_id(string username)
        {
            DB db = new DB();
            var u = (from c in db.tblMembers where c.username.Equals(username) select c.mem_id).ToList();
            int mem_id = Convert.ToInt32(u[0]);
            return mem_id;
        }

        public int update_avarta(string avarta, string username)
        {
            DB db = new DB();
            return db.sp_update_avarta(username, avarta);
        }
        //Get member's contact
        public List<sp_get_mem_contact_by_idResult> get_mem_contact(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_mem_contact_by_id(mem_id).ToList();
        }
        //Get Member's jobs
        public List<sp_get_job_by_idResult> get_job_info(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_job_by_id(mem_id).ToList();
        }
        //Get member's school
        public List<sp_get_school_by_idResult> get_school_info(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_school_by_id(mem_id).ToList();
        }
        //Get member's address
        public List<sp_get_address_by_idResult> get_address_info(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_address_by_id(Convert.ToInt32(mem_id.ToString())).ToList();
        }
        //Get member's interest
        public List<sp_get_interest_by_idResult> get_interest_info(int mem_id)
        {
            DB db = new DB();
            return db.sp_get_interest_by_id(mem_id).ToList();
        }
        
    }
}
